import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import { Table, Spin, Form, Row, Col, Input, Button, Select, TreeSelect, DatePicker, Checkbox, message, Dropdown, Menu, Icon } from 'antd'
import _ from 'lodash'
import moment from 'moment'

import Ajax from 'lib/Ajax'
import { addConfig } from 'actions/config'
import { getNewTreeData, findRowData, getNameByCode, confirmDelete } from 'lib/fun'

const FormItem = Form.Item;
const SelectTreeNode = TreeSelect.TreeNode;
const Option = Select.Option;
const { RangePicker } = DatePicker;

class Filter extends Component {
  constructor(props) {
    super(props);
    this.state = {
      
    }
  }

  componentDidMount(){

  }

  componentWillReceiveProps(nextProps){
    if(!nextProps.visible){
      this.props.form.resetFields();
    }
  }

  handleSearch = (e) => {
    var self = this;
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      self.props.handleFilter(values);
    });
  }

  handleReset = () => {
    this.props.form.resetFields();
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    };
    const { type } = this.props;
    return (<div className="ant-advanced-search-form">
          <Row>
            <Col span={6}>
              <FormItem {...formItemLayout} label="用户姓名">
                {getFieldDecorator("name")(
                  <Input />
                )}
              </FormItem>
            </Col>
            <Col span={6}>
              <FormItem {...formItemLayout} label="身份证">
                {getFieldDecorator("identNumber")(
                  <Input />
                )}
              </FormItem>
            </Col>
            <Col span={6}>
              <FormItem {...formItemLayout} label="状态">
                {getFieldDecorator("state",{
                  initialValue: type == 'org'?["50"]:["20"]
                })(
                  <Select
                    multiple
                    size="default"
                    style={{ width: '100%' }}
                    dropdownMatchSelectWidth={false}
                  >
                    {type == 'org'?<Option key="50">主管部门待审批</Option>:<Option key="20">乡镇登记待复核</Option>}
                    {type == 'org'?<Option key="60">主管部门审批通过，待汇总上报</Option>:<Option key="30">乡镇登记复核通过，待上报</Option>}
                    {type == 'org'?<Option key="70">主管部门审批不通过</Option>:<Option key="40">乡镇复核不通过</Option>}
                  </Select>
                )}
              </FormItem>
            </Col>
            <Col span={6}>
              <div className="btn-group">
                <Button type="primary" onClick={this.handleSearch}>查询</Button>
                <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
                  重置
                </Button>
              </div>
            </Col>
          </Row>
        </div>);
  }
}

module.exports = Form.create()(Filter)